package com.trippartner.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.logical.shared.ResizeEvent;
import com.google.gwt.event.logical.shared.ResizeHandler;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.RootPanel;

public class MyTripPartnerModule implements EntryPoint, ValueChangeHandler<String> {
	/**
	 * The message displayed to the user when the server cannot be reached or
	 * returns an error.
	 */
	private static final String SERVER_ERROR = "An error occurred while " + "attempting to contact the server. Please check your network "
			+ "connection and try again.";

	private MainPresenter mainPresenter;

	private com.google.web.bindery.event.shared.SimpleEventBus eventBus;

	public MyTripPartnerModule() {
		super();
	}

	public MyTripPartnerModule(final HandlerManager eventBus) {
		History.addValueChangeHandler(this);
	}

	/**
	 * This is the entry point method.
	 */
	public void onModuleLoad() {
		mainPresenter = new MainPresenter(new MainView(), eventBus = new com.google.web.bindery.event.shared.SimpleEventBus());
		Window.enableScrolling(false);
		Window.setMargin("0px");
		mainPresenter.go(RootPanel.get());
		registerHandler();
	}

	public void onValueChange(ValueChangeEvent<String> event) {
		// TODO Auto-generated method stub
	}

	private void registerHandler() {
		Window.addResizeHandler(new ResizeHandler() {
			public void onResize(ResizeEvent event) {
				eventBus.fireEvent(event);
			}
		});
	}
}
